package com.ruoyi.web.controller.wxpay;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.weixin.domain.KssVipSettings;
import com.ruoyi.weixin.service.IKssVipSettingsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 微信支付vipController
 * 
 * @author cfw
 * @date 2021-10-07
 */
@Controller
@RequestMapping("/weixin/settings")
public class KssVipSettingsController extends BaseController
{
    private String prefix = "weixin/settings";

    @Autowired
    private IKssVipSettingsService kssVipSettingsService;

    @RequiresPermissions("weixin:settings:view")
    @GetMapping()
    public String settings()
    {
        return prefix + "/settings";
    }

    /**
     * 查询微信支付vip列表
     */
    @RequiresPermissions("weixin:settings:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KssVipSettings kssVipSettings)
    {
        startPage();
        List<KssVipSettings> list = kssVipSettingsService.selectKssVipSettingsList(kssVipSettings);
        return getDataTable(list);
    }

    /**
     * 导出微信支付vip列表
     */
    @RequiresPermissions("weixin:settings:export")
    @Log(title = "微信支付vip", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KssVipSettings kssVipSettings)
    {
        List<KssVipSettings> list = kssVipSettingsService.selectKssVipSettingsList(kssVipSettings);
        ExcelUtil<KssVipSettings> util = new ExcelUtil<KssVipSettings>(KssVipSettings.class);
        return util.exportExcel(list, "微信支付vip数据");
    }

    /**
     * 新增微信支付vip
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存微信支付vip
     */
    @RequiresPermissions("weixin:settings:add")
    @Log(title = "微信支付vip", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KssVipSettings kssVipSettings)
    {
        return toAjax(kssVipSettingsService.insertKssVipSettings(kssVipSettings));
    }

    /**
     * 修改微信支付vip
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        KssVipSettings kssVipSettings = kssVipSettingsService.selectKssVipSettingsById(id);
        mmap.put("kssVipSettings", kssVipSettings);
        return prefix + "/edit";
    }

    /**
     * 修改保存微信支付vip
     */
    @RequiresPermissions("weixin:settings:edit")
    @Log(title = "微信支付vip", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KssVipSettings kssVipSettings)
    {
        return toAjax(kssVipSettingsService.updateKssVipSettings(kssVipSettings));
    }

    /**
     * 删除微信支付vip
     */
    @RequiresPermissions("weixin:settings:remove")
    @Log(title = "微信支付vip", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(kssVipSettingsService.deleteKssVipSettingsByIds(ids));
    }
}
